package com.itheima.反射reflect.基于反射方式操作成员变量;

import java.lang.reflect.Field;
import java.util.ArrayList;

public class ReflectArrayListDemo3 {
    public static void main(String[] args)throws Exception {
        Class clazz = Class.forName("java.util.ArrayList");
        Field size = clazz.getDeclaredField("size");
        size.setAccessible(true);
        ArrayList list = (ArrayList) clazz.newInstance();
        size.set(list,6);
        Object value = size.get(list);
        System.out.println("value="+value);

        list.add("我是list集合第6索引位置元素");
        System.out.println("list="+list);
    }
}
